from typing import Optional

from model.uml_element import UmlElement

from model.uml_opaque_expression import UmlOpaqueExpression

from model.uml_xmi_info import UmlXmiInfo


class UmlConstraint(UmlElement):
    def __init__(self) -> None:
        """
        ownerRule
        """
        super().__init__(UmlXmiInfo.type_constraint)
        self.name: str = ""
        self.constrainedElement: str = ""
        self.specification: Optional[UmlOpaqueExpression] = None

    def to_json(self) -> dict[str, object]:
        json: dict = super().to_json()
        json["name"] = self.name
        json["constrainedElement"] = self.constrainedElement

        if self.ownedComment is not None:
            json["ownedComment"] = self.ownedComment.to_json()

        if self.specification is not None:
            json["specification"] = self.specification.to_json()

        return json
